package com.cykj.controller;

import com.cykj.util.ImageCodeUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @BelongsProject: jx2408-maven3
 * @BelongsPackage: com.cykj.controller
 * @Author: 小林
 * @CreateTime: 2025-01-10 14:23
 * @Description: 登录页面验证码图片
 * @Version: 1.0
 */
@RestController
public class CodeController {
    /**
     * 验证码
     * @param response
     * @param httpSession
     * @throws IOException
     */
    @RequestMapping("/code")
    public void getCode(HttpServletResponse response, HttpSession httpSession) throws IOException {
         ImageCodeUtils imageCodeUtils = new ImageCodeUtils();
        System.err.println(imageCodeUtils.getCode());
         httpSession.setAttribute("code",imageCodeUtils.getCode());
        imageCodeUtils.write(response.getOutputStream());
    }
}

